package com.teamone.etl.admin.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;
import com.teamone.etl.admin.feign.EnterpriseWebService;
import com.teamone.etl.enterprise.entity.AlarmPhone;
import com.teamone.etl.enterprise.entity.Enterprise;
import com.teamone.etl.enterprise.request.EnterpriseRequest;
import com.teamone.etl.exception.CustomException;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 @author WangZhuoRan */
@RestController
@RequestMapping("/admin/enterprise")
public class EnterpriseWebController {

    @Resource
    private EnterpriseWebService service;

    @PostMapping("/getEnterpriseList")
    public R<PageInfo<Enterprise>> getEnterpriseList (@RequestBody EnterpriseRequest request) throws CustomException {
        return service.getEnterpriseList(request);
    }

    @PutMapping("/updateEnterprise")
    public R<Boolean> updateEnterprise (@RequestBody EnterpriseRequest request) throws CustomException {
        return service.updateEnterprise(request);
    }

    @PostMapping("/addEnterprise/{flag}")
    public R<Boolean> addEnterprise (@RequestBody EnterpriseRequest request,
                                     @PathVariable(value = "flag",required = false) Integer flag) throws CustomException {
        return service.addEnterprise(request, flag);
    }

    @PostMapping(value = "/uploadLicenseImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<String> uploadLicenseImage(@RequestPart("file") MultipartFile file) throws CustomException {
        return service.uploadLicenseImage(file);
    }

    @PostMapping(value = "/uploadEnterpriseImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<String> uploadEnterpriseImage(@RequestPart("file") MultipartFile file) throws CustomException {
        return service.uploadEnterpriseImage(file);
    }

    @GetMapping("/getAlarmList/{enterpriseId}")
    public R<List<AlarmPhone>> getEnterpriseList (@PathVariable(name = "enterpriseId") Integer enterpriseId) throws CustomException{
        return service.getAlarmList(enterpriseId);
    }

    @PostMapping("/addAlarm")
    public R<Boolean> addEnterprise (@RequestBody AlarmPhone alarmPhone) throws CustomException {
        return service.addAlarm(alarmPhone);
    }

    @DeleteMapping("/deleteAlarm/{id}")
    public R<Boolean> delete(@PathVariable(name = "id") Integer id) throws CustomException{
        return service.deleteAlarm(id);
    }

}
